package yt.kpool.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import java.math.BigDecimal;
import java.util.List;
import yt.kpool.R;
import yt.kpool.activity.home.HomeSecondDetailAc;
import yt.kpool.bean.PowBean;
import yt.kpool.network.NetHelperNew;
import yt.kpool.util.Util;
import yt.kpool.util.imageUtil.GlideUtil;

public class PowAdapter extends BaseQuickAdapter<PowBean.DataBean.CoinListBean, BaseViewHolder> {
    private Context context;
    private Double Exchange;
    private int kind,type;
    private double flash_p=0.00;//电费
    public PowAdapter(Context context,@Nullable List<PowBean.DataBean.CoinListBean> data) {
        super(R.layout.adapter_pow, data);
        this.context=context;

    }

    @Override
    protected void convert(BaseViewHolder helper, final PowBean.DataBean.CoinListBean item) {
        GlideUtil.loadImage(context, NetHelperNew.URL + item.getIcon(), (ImageView) helper.getView(R.id.iv_coin), R.mipmap.ic_launcher, R.mipmap.ic_launcher);
        helper.setText(R.id.tv_name, item.getCode().toUpperCase());
        TextView tv_num=helper.getView(R.id.tv_num);
        if(helper.getAdapterPosition()<9)
        {
            tv_num.setText("0"+(helper.getAdapterPosition()+1));
        }
        else
        {
            tv_num.setText(helper.getAdapterPosition()+1+"");
        }




        helper.setText(R.id.tv_Algorithm, item.getAlgorithm()+"");



        BigDecimal c1 = new BigDecimal(item.getPrice());
        BigDecimal c2 = new BigDecimal(Exchange);
        String cp1=c1.multiply(c2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"";


        ImageView tv_PriceTrend=helper.getView(R.id.tv_PriceTrend);
        TextView tv_NetworkHashrate=helper.getView(R.id.tv_NetworkHashrate);

        if(item.getPriceChange24h()>0)
        {
            tv_PriceTrend.setImageResource(R.mipmap.shangzhang);
            tv_NetworkHashrate.setTextColor(Color.parseColor("#2b9054"));
        }
        else if(item.getPriceChange24h()<0)
        {
            tv_PriceTrend.setImageResource(R.mipmap.xiadie);
            tv_NetworkHashrate.setTextColor(Color.parseColor("#ff003c"));
        }


        tv_NetworkHashrate.setText(Util.GetTNumber(item.getPriceChange24h()+"")+"%");
        TextView tv_coinkind=helper.getView(R.id.tv_coinkind);



       if(kind==1)//人民币
        {

            tv_coinkind.setText("¥");
            helper.setText(R.id.tv_coinprice, cp1);
            helper.setText(R.id.tv_mcion, "¥");
            BigDecimal bi1 = new BigDecimal(item.getMarketCap()*Exchange);
            BigDecimal bi2 = new BigDecimal(100000000);
            String str= bi1.divide(bi2).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()+"";
            helper.setText(R.id.tv_Marketcap, str+"亿");
            BigDecimal bi11 = new BigDecimal(item.getOutput24h()*Exchange);
            BigDecimal bi22 = new BigDecimal(10000);
            String strr= bi11.divide(bi22).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"";
            helper.setText(R.id.tv_Output24h, "¥"+strr+"万");
        }
        else if (kind==2)//美元
        {
            tv_coinkind.setText("$");
            helper.setText(R.id.tv_coinprice, Util.GetTNumber(item.getPrice()+""));
            helper.setText(R.id.tv_mcion, "$");
            BigDecimal bi1 = new BigDecimal(item.getMarketCap());
            BigDecimal bi2 = new BigDecimal(100000000);
            String str= bi1.divide(bi2).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()+"";

            helper.setText(R.id.tv_Marketcap, str+"亿");
            BigDecimal bi11 = new BigDecimal(item.getOutput24h());
            BigDecimal bi22 = new BigDecimal(10000);
            String strr= bi11.divide(bi22).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()+"";

            helper.setText(R.id.tv_Output24h, "$"+strr+"万");
        }
        helper.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HomeSecondDetailAc.start(context,item.getID()+"");
            }
        });
//
    }

    /**
     * 设置转换
     * @param Exchange
     */
    public void setExchange(Double Exchange)
    {
        this.Exchange=Exchange;
    }

    /**
     * 设置币种
     * @param kind
     */
    public void setKind(int kind,double flash_p)
    {
        this.kind=kind;
        this.flash_p=flash_p;

    }

}
